package com.jadcon.harveycedars.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.jadcon.harveycedars.model.dormitory.Person;
import com.jadcon.harveycedars.model.dormitory.PersonService;

@Controller
public class PersonController {

	@Autowired
	private PersonService personService;

	@RequestMapping("/person.html")
	public ModelAndView person() {
		System.out.println("PersonController.person() begin...");
		
		// get data from model
		List<Person> personList = personService.getPersonList();
		
		// add data to ModelAndView
		ModelAndView mav = new ModelAndView("person"); // "person" is the view name
		mav.addObject("personList", personList);
		return mav;
	}
	
	@RequestMapping("/personsearch.html")
	public ModelAndView personSearch(@RequestParam String fullname) {
		System.out.println("PersonController.personSearch() begin...");
		
		// get data from model
		Person person = personService.findPersonByFullName(fullname);
		
		
		// add data to ModelAndView
		ModelAndView mav = new ModelAndView("persondetail"); // "persondetail" is the view name
		mav.addObject("person", person);
		return mav;
	}
		// map ("key", value)
	
}
